package ac.github.os.internal.core.script.impl

import ac.github.os.internal.core.script.BaseWrapper
import ac.github.os.internal.core.script.InternalConfig
import ac.github.os.internal.core.script.InternalScript
import ac.github.os.internal.core.trigger.EntityTrigger
import ac.github.os.internal.core.trigger.PlayerTrigger
import ac.github.os.internal.core.trigger.Trigger
import org.bukkit.Bukkit
import org.bukkit.entity.LivingEntity
import org.bukkit.event.entity.EntityDamageByEntityEvent
import org.bukkit.event.entity.EntityDamageEvent

class GenerateScript : InternalScript<GenerateScript.Wrapper> {

    class Wrapper : BaseWrapper

    override val name: String
        get() = "generate"

    override fun execute(trigger: Trigger?, wrapper: Wrapper, config: InternalConfig, string: String): String {

        return when (string) {
            "damage" -> {
                if (trigger is EntityTrigger) {
                    val event = EntityDamageByEntityEvent(
                        trigger.entity,
                        trigger.entity,
                        EntityDamageEvent.DamageCause.ENTITY_ATTACK,
                        0.0
                    )
                    Bukkit.getPluginManager().callEvent(event)
                    event.damage.toString()
                } else "0.0"
            }
            else -> "0.0"
        }
    }

}